import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sainbainu/common/values/colors.dart';

import '../index.dart';
import 'widgets.dart';

class CodeLogin extends GetView<LoginController> {
  final VoidCallback onLogin;
  final VoidCallback onEazyLogin;
  final VoidCallback onPwdLogin;
  final VoidCallback onCodeBtnPressed;

  const CodeLogin({
    Key? key,
    required this.onLogin,
    required this.onEazyLogin,
    required this.onPwdLogin,
    required this.onCodeBtnPressed,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        const LoginTitle('手机登录'),
        const SizedBox(height: 50),
        CustomInput(
          controller: controller.state.mobileController,
          hintText: '输入手机号',
          keyboardType: TextInputType.phone,
        ),
        const SizedBox(height: 10),
        CustomInput(
          controller: controller.state.codeController,
          hintText: '输入验证码',
          keyboardType: TextInputType.number,
          suffixIcon: Padding(
            padding: const EdgeInsets.all(4),
            child: SizedBox(
              width: 90,
              child: Obx(
                () => ElevatedButton(
                  style: ElevatedButton.styleFrom(
                    backgroundColor: AppColors.danger,
                    foregroundColor: Colors.white,
                    padding: const EdgeInsets.all(0),
                    disabledForegroundColor: AppColors.unactive,
                  ),
                  onPressed: controller.state.isSending.value
                      ? null
                      : onCodeBtnPressed,
                  child: controller.state.isSending.value
                      ? Text('${controller.state.smsSeconds.value}s')
                      : Text('短信获取'.tr),
                ),
              ),
            ),
          ),
        ),
        const SizedBox(height: 50),
        LoginBtn(
          text: '登录',
          onPressed: onLogin,
        ),
        const SizedBox(height: 20),
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            LoginTextBtn(
              text: '一键登录',
              onPressed: onEazyLogin,
            ),
            LoginTextBtn(
              text: '密码登录',
              onPressed: onPwdLogin,
            ),
          ],
        ),
      ],
    );
  }
}
